package Thread_Runable;

public class MyThread implements Runnable {

	private static int ticket = 100;
	private Object obj = new Object();

	@Override
	public void run() {
		while (true) {
			SellTicket();

		}

	}

	private static void SellTicket() {
		synchronized (MyThread.class) {
			if (ticket > 0) {
				System.out.println("在" + Thread.currentThread().getName() + "还有" + ticket + "张票");
			}
			ticket--;
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}
